home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / other / h2a / Hist.c < prev    next >
C/C++ Source or Header  |  1991-02-26  |  5KB  |  233 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "net.h"
  4. #include "globals.h"
  5. #include "history.h"
  6.  
  7.  
  8. public    hptr   freeHist = NULL;        /* list of free history entries */
  9. public  hptr   last_hist;        /* pointer to dummy hist-entry that
  10.                      * serves as tail for all nodes */
  11. public    hptr    first_model;        /* first model entry */
  12. public    Ulong    max_time;
  13.  
  14. private    char    inp_chars[] = " i";
  15. private    char    node_name[256];
  16. private    int    skip_it = 0;
  17. extern    phist    *Sort();
  18.  
  19.  
  20. private struct
  21.   {
  22.     phist  first;
  23.     phist  *last;
  24.     int    num;
  25.     char   *sv_name;
  26.   } theHistory = { NULL, &theHistory.first, 0, NULL };
  27.  
  28.  
  29. private void NewHist( tm, delay, rtime, ptime, val, type, name )
  30.   long  tm;
  31.   int   delay, rtime, ptime, val, type;
  32.   char  *name;
  33.   {
  34.     static phist  hfree = NULL;
  35.     phist         new;
  36.  
  37.     if( (new = hfree) == NULL )
  38.     new = (phist) MallocList( sizeof( History ), 1 );
  39.     hfree = new->next;
  40.     new->time = tm;
  41.     new->delay = delay;
  42.     new->rtime = rtime;
  43.     new->ptime = ptime;
  44.     new->name = (type == H_PEND) ? theHistory.sv_name : name;
  45.     new->val = vchars[ val ];
  46.     new->type = type;
  47.     *theHistory.last = new;
  48.     theHistory.last = &new->next;
  49.     theHistory.num ++;
  50.     if( type == H_FIRST or type == H_FIRST_INP )
  51.     theHistory.sv_name = name;
  52.   }
  53.  
  54.  
  55. public void sortAndPrint()
  56.   {
  57.     phist     *data;
  58.     long      maxv = 0;
  59.     register phist  *arrp, p;
  60.  
  61.     if( theHistory.first == NULL )
  62.       {
  63.     if( only_name != NULL )
  64.         fprintf( stderr, "%s: NOT found\n", only_name );
  65.     else
  66.         fprintf( stderr, "EMPTY HISTORY?\n" );
  67.     exit( 0 );
  68.       }
  69.     *theHistory.last = NULL;
  70.     data = (phist *) Valloc( (theHistory.num + 1) * sizeof( phist * ), 1 );
  71.     for( arrp = data, p = theHistory.first; p != NULL; p = p->next )
  72.       {
  73.     *arrp++ = p;
  74.     if( p->time > maxv ) maxv = p->time;
  75.       }
  76.     *arrp = NULL;
  77.  
  78.     data = Sort( theHistory.num, data, maxv );
  79.  
  80.     for( arrp = data; (p = *arrp) != NULL; arrp++ )
  81.       {
  82.     printf( "%10.1f  %c%c", d2ns( p->time ), p->val, " i ipP"[p->type] );
  83.     if( p->type <= H_FIRST_INP )
  84.       {
  85.         if( do_delay )    printf( "      --" );
  86.         if( do_rtime )    printf( "      --" );
  87.       }
  88.     else
  89.       {
  90.         if( do_delay )    printf( "%8.1f", d2ns( p->delay ) );
  91.         if( do_rtime )    printf( "%8.1f", d2ns( p->rtime ) );
  92.         if( p->type == H_PUNT and do_delay )
  93.         printf( "  (%.1f)", d2ns( p->time - p->ptime ) );
  94.       }
  95.     printf( "  %s\n", p->name );
  96.       }
  97.   }
  98.  
  99.  
  100. public void init_hist()
  101.   {
  102.     static HistEnt  dummy;
  103.     static HistEnt  dummy_model;
  104.  
  105.     max_time = MAX_TIME;
  106.  
  107.     last_hist = &dummy;
  108.     dummy.next = last_hist;
  109.     dummy.time = max_time;
  110.     dummy.val = X;
  111.     dummy.inp = 1;
  112.     dummy.punt = 0;
  113.     dummy.t.r.delay = dummy.t.r.rtime = 0;
  114.   }
  115.  
  116. public void FreeHistList( node ) nptr node; {}
  117.  
  118.  
  119. public void SetFirstHist( node, val, inp, time )
  120.   nptr  node;
  121.   int   val, inp;
  122.   long  time;
  123.   {
  124.     if( only_name != NULL )
  125.       {
  126.     if( skip_it == 2 )        /* all_done */
  127.       {
  128.         if( do_sort ) sortAndPrint();
  129.         exit( 0 );
  130.       }
  131.     skip_it = (str_eql( only_name, node->nname ) == 0) ? 2 : 1;
  132.     if( skip_it == 1 )
  133.         return;
  134.       }
  135.  
  136.     if( do_sort )
  137.       {
  138.     NewHist( time, 0, 0, 0, val, H_FIRST + inp, node->nname );
  139.     return;
  140.       }
  141.  
  142.     (void) strcpy( node_name, node->nname );
  143.  
  144.     if( not do_names )
  145.     printf( "\n%s\n", node_name );
  146.  
  147.     printf( "%10.1f  %c%c", d2ns( time ), vchars[ val ], inp_chars[ inp ] );
  148.     if( do_delay )
  149.     printf( "      --" );
  150.     if( do_rtime )
  151.     printf( "      --" );
  152.     if( do_names )
  153.     printf( "  %s", node_name );
  154.     putchar( '\n' );
  155.   }
  156.  
  157.  
  158. public void AddHist( node, val, inp, time, delay, rtime )
  159.   nptr  node;
  160.   int   val, inp;
  161.   long  time, delay, rtime;
  162.   {
  163.     if( skip_it == 1 )
  164.     return;
  165.  
  166.     if( do_sort )
  167.       {
  168.     NewHist( time, (int) delay, (int) rtime, 0, val, H_NORM + inp,
  169.       node->nname );
  170.     return;
  171.       }
  172.     printf( "%10.1f  %c%c", d2ns( time ), vchars[ val ], inp_chars[ inp ] );
  173.     if( do_delay )
  174.     printf( "%8.1f", d2ns( delay ) );
  175.     if( do_rtime )
  176.     printf( "%8.1f", d2ns( rtime ) );
  177.     if( do_names )
  178.     printf( "  %s", node_name );
  179.     putchar( '\n' );
  180.   }
  181.  
  182.  
  183. public void AddPunted( node, ev, delta )
  184.   nptr   node;
  185.   evptr  ev;
  186.   long   delta;
  187.   {
  188.     if( skip_it == 1 )
  189.     return;
  190.  
  191.     if( do_sort )
  192.       {
  193.     NewHist( ev->ntime, (int) ev->delay, (int) ev->rtime,
  194.       ev->ntime - delta, ev->eval, H_PUNT, node->nname );
  195.     return;
  196.       }
  197.     printf( "%10.1f  %cp", d2ns( ev->ntime ), vchars[ ev->eval ] );
  198.     if( do_delay )
  199.     printf( "%8.1f", d2ns( ev->delay ) );
  200.     if( do_rtime )
  201.     printf( "%8.1f", d2ns( ev->rtime ) );
  202.     if( do_delay )
  203.     printf( "  (%.1f)", d2ns( delta ) );
  204.     if( do_names )
  205.     printf( "  %s", node_name );
  206.     putchar( '\n' );
  207.   }
  208.  
  209.  
  210. public void enqueue_event( node, val, delay, rtime )
  211.   nptr  node;
  212.   int   val;
  213.   long  delay, rtime;
  214.   {
  215.     if( skip_it == 1 )
  216.     return;
  217.  
  218.     if( do_sort )
  219.       {
  220.     NewHist( cur_delta + delay, (int) delay, (int) rtime, 0, val, H_PEND,
  221.       node->nname );
  222.     return;
  223.       }
  224.     printf( "%10.1f  %cP", d2ns( cur_delta + delay ), vchars[ val ] );
  225.     if( do_delay )
  226.     printf( "%8.1f", d2ns( delay ) );
  227.     if( do_rtime )
  228.     printf( "%8.1f", d2ns( rtime ) );
  229.     if( do_names )
  230.     printf( "  %s", node_name );
  231.     putchar( '\n' );
  232.   }
  233.